// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-12-02

package app

type (
	// Status
	// is a type name for norma.
	Status     int
	StatusText string
)

// Status enumerates.

const (
	StatusDisabled Status = iota
	StatusEnabled
)

const (
	StatusTextDisabled StatusText = "disabled"
	StatusTextEnabled  StatusText = "enabled"
)

var (
	statusText = map[Status]StatusText{
		StatusDisabled: StatusTextDisabled,
		StatusEnabled:  StatusTextEnabled,
	}
	statusTextUnknown StatusText = ""
)

func (o Status) Disabled() bool { return o == StatusDisabled }
func (o Status) Enabled() bool  { return o == StatusEnabled }

func (o Status) Text() string {
	if s, ok := statusText[o]; ok {
		return s.String()
	}
	return statusTextUnknown.String()
}

func (o StatusText) Can() (status Status, has bool) {
	switch o {
	case StatusTextDisabled:
		return StatusDisabled, true
	case StatusTextEnabled:
		return StatusEnabled, true
	}
	return
}

func (o StatusText) String() string { return string(o) }
